package com.hcy.rabbitmanagerapi.controller;

import com.hcy.manager.dto.request.CarInfoRequestDTO;
import com.hcy.manager.dto.response.CarInfoResponseDTO;
import com.hcy.rabbitbasicmodel.dto.MyPage;
import com.hcy.rabbitbasicmodel.enums.Clients;
import com.hcy.rabbitbasicmodel.model.ResponseData;
import com.hcy.rabbitbasicmodel.model.ReturnResult;
import com.hcy.rabbitbasicmodel.signl.Query;
import com.hcy.userclient.client.UserAuthClient;
import com.hcy.usermodel.dto.request.UserAuthRequestDTO;
import com.hcy.usermodel.dto.response.UserAuthsResponseDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author huchenying
 * @Description
 * @Date 2022/5/8
 **/
@RestController
@Slf4j
@RequestMapping("/customer")
public class CustomerController {

    @Autowired
    UserAuthClient userAuthClient;

    @PostMapping("/getCustomerList")
    public ReturnResult getCustomerList(@Validated(Query.class) @RequestBody UserAuthRequestDTO requestDTO) {
        log.info("getCustomerList start param -> {}", ToStringBuilder.reflectionToString(requestDTO));
        try {
            requestDTO.setBusinessCode(Clients.CUSTOMER.getName());
            ResponseData<MyPage<UserAuthsResponseDTO>> customerList = userAuthClient.getCustomerList(requestDTO);
            if (customerList.getCode().noSuccess()) {
                return ReturnResult.fail("系统繁忙");
            }
            return ReturnResult.success().setData(customerList.getData());
        } catch (Exception e) {
            log.error("系统繁忙");
            return ReturnResult.fail("系统繁忙");
        }
    }
}
